<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">菜单管理</h3>
				<div class="box-tools pull-right">
						<@shiro.hasPermission name="menu:add">
                            <a  class="btn btn-sm btn-primary" id="addUrl" target="modal" modal="lg" href="/admin/wx/menu/add">添加</a>
                            <a  class="btn btn-sm btn-primary" callback="retrunWxSync();" data-body="开始同步？" target="ajaxTodo" href="/admin/wx/menu/sync">同步到微信</a>
						</@shiro.hasPermission>
				</div>
			</div>
			<div class="box-body">
                <div class="col-md-12">
				<table id="tb_tab" class="table table-bordered table-striped">
					<thead>
						<tr>
							<tr>
								<th>菜单名称</th>
								<th>菜单类型</th>
                            	<th>菜单位置</th>
								<th>是否显示</th>
								<th>操作</th>
							</tr>
						</tr>
					</thead>
				</table>
				</div>
			</div>
		</div>
	</div>
</div>


<script type="text/javascript">
var ajax_tab;

$(function() {

	//初始化表格
    ajax_tab = $('#tb_tab').DataTable({
        "dom":'itflp',
        "processing":true,
        "searching":false,
        "bInfo":false,
        "bServerSide":false,
        "paging":false,
        "bSort":false,
		"language":{"url":"plugins/datatables/language.json"},
		"ajax":{"url":"/admin/wx/menu/page","type":"post"},
		"columns":[
			{"data":null},
            {"data":"type"},
            {"data":"orders"},
            {"data":"status"},
			{"data":null}
			],
		"columnDefs":[
            {
                targets: 0,
                data: null,
                render: function (data) {
					if (data.orders.length == 2){
						return "└─"+data.name;
					}else {
						return data.name;
					}
                }
            },
            {
                targets: 2,
                data: null,
                render: function (data) {
                    return getMenuOrder(data);
                }
            },
			{
			    targets: 3,
			    data: null,
			    render: function (data) {
			    	if(data == 0){
			    		return "否";
			    	}
			    	if(data == 1){
			    		return "是";
			    	}
			    	return "未知状态";
			    }
			},
            {
				"targets" : -1,
				"data" : null,
				"render" : function(data) {
					var btn = '<@shiro.hasPermission name="menu:edit">'
							+'<a class="btn btn-xs btn-info"  target="modal"  modal="lg" href="/admin/wx/menu/edit?id='+ data.id+'">修改</a>&nbsp;'
							+'</@shiro.hasPermission>'
							+'<@shiro.hasPermission name="menu:delete">'
							+'<a class="btn btn-xs btn-default " callback="tbReload();" data-body="确认要删除吗？" target="ajaxTodo" href="/admin/wx/menu/delete?id='+ data.id +'">删除</a>';
						    +'</@shiro.hasPermission>'
						return btn;
				}
		} ]
	}).on('xhr.dt', function ( e, settings, data ,xhr) {
        dataTableMsg(data,xhr);
    } );
});

function retrunWxSync() {
	alertMsg("同步完成","success");
}

function tbReload(){
    var param = {};
    ajax_tab.settings()[0].ajax.data = param;
    ajax_tab.ajax.reload();
}

function getMenuOrder(order) {
	var menuName = "";
    switch (order){
		<#list ordersList as item>
		case "${item.value}": menuName="${item.name}";break;
		</#list>
}
	return menuName;
}

</script>